import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: AliceMana
 * Date: 2023-01-09
 * Time: 18:09
 */
public class Solution {
    // https://leetcode.cn/problems/next-greater-element-i/
    public static int[] nextGreaterElement(int[] nums1, int[] nums2) {
        int[] res = new int[nums1.length];
        List<Integer> list = new LinkedList<>();
        for (Integer x : nums2) {
            list.add(x);
        }
        int r = 0;
        for (int n : nums1) {
            int tmp = r;
            for (int j = list.indexOf(n); j < nums2.length; j++) {
                if (nums2[j] > n) {
                    res[r++] = nums2[j];
                    break;
                }
            }
            if (tmp == r) {
                res[r++] = -1;
            }
        }
        return res;
    }

    public static void main(String[] args) {
        int[] n1 = {2,4};
        int[] n2 = {1,2,3,4};
        System.out.println(Arrays.toString(nextGreaterElement(n1, n2)));
    }


    // https://leetcode.cn/problems/build-an-array-with-stack-operations/
    public static List<String> buildArray(int[] target, int n) {
        List<String> list = new LinkedList<>();
        int j = 0;
        for (int i = 1; i <= n; i++) {
            if (target[target.length-1] + 1 == i) {
                break;
            }
            if (target[j] == i) {
                list.add("Push");
                j++;
            } else {
                list.add("Push");
                list.add("Pop");
            }
        }
        return list;
    }

    public static void main1(String[] args) {
        int[] target = {1,2};
        int n = 4;
        List<String> list = buildArray(target, n);
        for (String s : list) {
            System.out.println(s);
        }
    }
}
